﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.Shell;
using AxlfVSX.Core;
using EnvDTE;
using Aoxuelf.MDSTool.UI;
using System.Windows.Forms;

namespace Aoxuelf.MDSTool.Commands
{
    [CommandID(GuidList.guidMDSToolCmdSetString, PkgCmdIDList.cmdidInsertBLLQuery)]
    public class InsertBLLQueryCommand : DynamicCommand
    {
        public InsertBLLQueryCommand(Package package)
            : base(package)
        {
        }

        protected override bool CanExecute(OleMenuCommand command)
        {
            try
            {
                return FileCodeModelHelper.IsServceClass(Dte);
            }
            catch
            {
                return false;
            }
        }

        protected override void OnExecute(OleMenuCommand command)
        {
            string sql = string.Empty;
            if (Clipboard.ContainsText())
            {
                sql = Clipboard.GetText();
                if (sql.IndexOf("select", StringComparison.CurrentCultureIgnoreCase) < 0)
                {
                    sql = string.Empty;
                }
            }

            InsertBLLQueryForm form = new InsertBLLQueryForm();
            form.ViewModel = new ViewModel.InsertDALSQLViewModel { MethodName = "QueryXX", Summary = "查询", SQL = sql };
            form.ShowDialog();
        }
    }
}
